/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package elaborate.tag_analysis.client.actions.reachability;

import elaborate.tag_analysis.client.graph.ClosureClusterBasedGraph;
import elaborate.tag_analysis.client.graph.Graph;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author lendle
 */
public class ReachabilityCalcTest {
    public Graph calculateReachability(Graph graph){
        try {
            Graph clonedGraph=graph.clone();
            List points=graph.getPoints();
           
            for(Object point : points){
                System.out.println(point);
                for(Object x : points){
                    for(Object y : points){
                        if(x.equals(y)){
                            continue;
                        }
                      
                        if(clonedGraph.isConnected(x, y)){
                            continue;
                        }
                        else if((clonedGraph.isConnected(x, point)) && clonedGraph.isConnected(point, y)){
                            clonedGraph.setConnected(x, y);
                        }
                    }
                }
            }
            return clonedGraph;
        } catch (CloneNotSupportedException ex) {
            Logger.getLogger(ReachabilityCalcTest.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }
    
    public static void main(String [] args) throws Exception{
        ClosureClusterBasedGraph g=new ClosureClusterBasedGraph();
        g.addPoint("A");
        g.addPoint("B");
        g.addPoint("C");
        g.addPoint("D");
        g.addPoint("E");
        g.addPoint("F");
        g.addPoint("G");
        
        g.setConnected("A", "B");
        g.setConnected("B", "C");
        g.setConnected("A", "D");
        g.setConnected("D", "E");
        g.setConnected("F", "G");
        //g.setConnected("B", "F");
        
        for(int i=0; i<3000; i++){
            g.addPoint("Point_"+i);
        }
        long startTime=System.currentTimeMillis();
        for(int i=0; i<g.getPoints().size(); i++){
            for(int i1=0; i1<g.getPoints().size(); i1++){
                if(i!=i1){
                    double test=Math.random();
                    if(test>=0.9){
                        //System.out.println("connected "+test+" "+"Point_"+i+" to "+"Point_"+i1);
                        g.setConnected("Point_"+i, "Point_"+i1);
                    }
                    
                }
            }
        }
        long okTime=System.currentTimeMillis();
        System.out.println(g.isConnected("A", "C")+":"+(okTime-startTime));
        System.out.println(g.isConnected("Point_1", "Point_9")+":"+g.getClusters().size());
        System.out.println(g.isConnected("A", "G")+":"+g.getClusters().size());
//        SimpleSparseGraph g=new SimpleSparseGraph();
//        g.setDirected(false);
//        g.getPoints().add("A");
//        g.getPoints().add("B");
//        g.getPoints().add("C");
//        g.setConnected("A", "B");
//        for(int i=0; i<2000; i++){
//            g.getPoints().add("Point_"+i);
//        }
//        
//        for(int i=0; i<g.getPoints().size(); i++){
//            for(int i1=0; i1<g.getPoints().size(); i1++){
//                if(i!=i1){
//                    double test=Math.random();
//                    if(test>=0.7){
//                        g.setConnected("Point_"+i, "Point_"+i1);
//                    }
//                    
//                }
//            }
//        }
//        System.out.println("start calc");
//        long startTime=System.currentTimeMillis();
//        ReachabilityCalc calc=new ReachabilityCalc();
//        Graph newGraph=calc.calculateReachability(g);
//        long okTime=System.currentTimeMillis();
//        System.out.println(newGraph.isConnected("A", "C")+":"+(okTime-startTime));
    }
}
